package com.woniuxy.tmsdriverassignment.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.woniuxy.tmsdriverassignment.domain.wDriver;
import com.woniuxy.tmsdriverassignment.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/4/20:15:18
 * <P> Description:
 */
@RestController
@RequestMapping("/driver")
public class DriverAssignmentController extends BaseController {
    @Autowired
    private DriverService driverService;

    //分配司机
    @PostMapping(value = "/adddriver/{waybill_id}/{driver_id}")
    public void addDriver(@PathVariable("waybill_id")int waybill_id,
                          @PathVariable("driver_id")int driver_id)
    {
//        System.out.println(request.getParameter("driverId")+"===========");
//        System.out.println("后端接收到新增请求--------"+wDriver.toString());
        driverService.addDriver(waybill_id,driver_id);
//        return AjaxResult.success("指定司机成功");
    }

    //查询所有未发运单
    @GetMapping("/all")
    public TableDataInfo allWDriver(wDriver wDriver){
//        System.out.println("请求成功");
       List<wDriver> list = driverService.getall(wDriver);
        startPage();
        return getDataTable(list);
    }

    //修改订单
    @PostMapping(value = "/update/{id}/{waybill_id}/{driver_id}")
    public AjaxResult updateOrder(@PathVariable("id")int id,
                                  @PathVariable("waybill_id")int waybill_id,
                                  @PathVariable("driver_id")int driver_id){
//        System.out.println(wDriver.getWaybill_id()+"+++++123456789");
        driverService.updateOrder(id,waybill_id,driver_id);
        return AjaxResult.success();
    }
    //删除
    @DeleteMapping ("/delete/{id}")
    public AjaxResult delete(@PathVariable("id")int id){
        driverService.delete(id);
        return AjaxResult.success();
    }
   //查询一个订单
    @GetMapping("/getOne/{id}")
    public AjaxResult getOne(@PathVariable("id") int id){
        wDriver one = driverService.getOne(id);
        return AjaxResult.success(one);
    }

}

